package com.vote.admin.controller;

import com.vote.common.returns.RespEntity;
import com.vote.admin.service.VoteUserDetailService;
import com.vote.admin.vo.record.OptionRecord;
import com.vote.admin.vo.result.VoteDetailResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 用户投票系统详情页 前端控制器
 * </p>
 *
 * @author gyg
 * @since 2021-05-18
 */
@RestController
@RequestMapping("/user-detail")
@Slf4j
@Api(value = "用户投票系统详情页", tags = "用户投票系统详情页")
public class VoteUserDetailController {

    @Resource
    private VoteUserDetailService voteUserDetailService;

    @GetMapping("/detail")
    @ApiOperation(value = "投票活动详情")
    @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "id", value = "投票活动id", required = true)
    public RespEntity<VoteDetailResult<List<OptionRecord>>> getVoteProjectInfo(@RequestParam(value = "id") Integer id) {
        RespEntity<VoteDetailResult<List<OptionRecord>>> respEntity = voteUserDetailService.getVoteProjectInfo(id);
        return respEntity;
    }

    @PutMapping("/vote")
    @ApiOperation(value = "投票")
    @ApiImplicitParam(paramType = "post", dataType = "Integer", name = "id", value = "投票选项id", required = true)
    public RespEntity<String> vote(@RequestParam(value = "id") Integer id, HttpServletRequest request) {
        RespEntity<String> respEntity = voteUserDetailService.vote(id, request);
        return respEntity;
    }



}
